package com.xiaomi.baidumap.github;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;


/**
 * 作者：yuanchao on 2016/8/24 0024 11:36
 * 邮箱：yuanchao@feicuiedu.com
 */
public class HotRepoAdapter extends FragmentPagerAdapter {

    private List<Language> languages;

    public HotRepoAdapter(FragmentManager fm,Context context) {
        super(fm);
        languages = Language.getDefaultLanguage(context);
    }

    @Override public Fragment getItem(int position) {
        //尽量不要在fragment中进行数据的传递,可以使用单例模式来传递数据
        return HotRepoListFragment.getInstance(languages.get(position));
    }

    @Override public int getCount() {
        //防止language为空
        return languages == null ? 0:languages.size();
    }

    @Override public CharSequence getPageTitle(int position) {

        return languages.get(position).getName();
    }
}
